//
// ResourceManager.h
// Usage: Kernel core component, manage all resource
// Create Date: 2009-03-05
// Author: MaJiuyue
//
#ifndef _RESOURCE_MANAGER_H_
#define _RESOURCE_MANAGER_H_

#include <stdlib.h>
#include "type.h"
#include "Map.h"
#include "Resource.h"

class CResourceManager : public Callable
{
public:
	CResourceManager();
	~CResourceManager();
	
#ifdef _DEBUG_
	void Dump();
#endif

public:
	/* Creates and returns resource ID or negative for error. */
	int CreateResource(Resource *pResource, const char * strResourceName = NULL);

	/* Request a resource object. */
	Resource * RequestResource(int iResourceID);
	Resource * RequestResource(const char * strResourceName);

	/* Removes a resource object from kernel. */
	void DestoryResource(int iResourceID);

private:
	typedef Map<u32, Resource*, 73> ResourceIdMap;
	typedef Map<const char *, Resource*, 73> ResourceNameMap;
	ResourceIdMap m_Resources;
	ResourceNameMap m_ResourceNameMap;

	/* Next created resource ID. */
	int iNextID;
};

extern CResourceManager ResourceManager;

#endif
